package za.co.chris.traintimes.beans;

import za.co.chris.traintimes.R;
import android.content.Context;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class TimeElement extends RelativeLayout {

	public String trainNumber;
	public String fromStation;
	public String toStation;
	public String startTime;
	public String endTime;
	SparseArray<String> stringValues = new SparseArray<String>();
	LayoutInflater layoutInflater;
	View inflatedView;

	public TimeElement(Context context) {
		super(context);
		layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflatedView = layoutInflater.inflate(R.layout.time_element, this);
	}

	public TimeElement(Context context, String trainNumber, String startTime, String endTime) {
		super(context);
		layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflatedView = layoutInflater.inflate(R.layout.time_element, this);
		this.trainNumber = trainNumber;
		this.startTime = startTime;
		this.endTime = endTime;
		setTexts(trainNumber, R.id.trainNumber);
		setTexts(startTime, R.id.startTime);
		setTexts(endTime, R.id.endTime);
	}

	public TimeElement(Context context, AttributeSet attrs) {
		super(context, attrs);
		layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflatedView = layoutInflater.inflate(R.layout.time_element, this);

	}

	private void setTexts(String text, int id) {
		TextView textView = (TextView) findViewById(id);
		if (textView != null) {
			textView.setText(text);
		}
		invalidate();
		requestLayout();
	}

}
